$(document).ready(function(){
    var menu_height=$(document).height();
    $("#left-menu").css("height",menu_height+"px");
    $.ajax({
        url: '/company_list',
        type: 'get',
        success: function(data,status){
            if(status == 'success'){
                //console.log(data);
                var str="";
                for(var i in data){
                    str+="<ul><li>"+(parseInt(i)+1)+"</li><li>"+data[i].name+"</li><li>"+data[i].business_field+"</li><li>"+data[i].reg_time+"</li><li><a href='/company_info?id="+data[i]._id+"'>详情</a></li></ul>"
                    $("#cms-uncheck-wrap").html(str);
                }
            }
        },
        error: function(data,err){
            console.log(data);
        }
    });
    //console.log(window.location.href);
    find_url_id();
    $.ajax({
        url: '/company_list',
        type: 'get',
        success: function(data,status){
            if(status == 'success'){
                console.log(data);
            }
        },
        error: function(data,err){
            console.log(data);
        }
    });
});

//左侧菜单始终保持100%高度
$(document).scroll(function(){
    var menu_height=$(document).height();
    $("#left-menu").css("height",menu_height+"px");
});

function topbtn(){
    if($("#topbar-ul").css("display")=="none"){
        $("#topbar-ul").css("display","block");
    }else{
        $("#topbar-ul").css("display","none");
    }
     
}
function find_url_id(){
    var url_str=window.location.href;
    var url_all=url_str.split("?")[1];
    var url_id=url_all.split("=")[1];
    console.log(url_id);
    $.ajax({
        url: '/company_list',
        type: 'get',
        success: function(data,status){
            if(status == 'success'){
                console.log(data);
                for(var i in data){
                    if(data[i]._id==url_id){
                        $("#cms-topname").html(data[i].name);
                        $("#cms-topname").attr("href","/company_info?id="+data[i]._id);
                        $("#info_name").val(data[i].name);
                        $("#info_fullname").val(data[i].fullname);
                        $("#info_address").val(data[i].address);
                        $("#info_website").val(data[i].website);
                        
                        $("#info_corporate").val(data[i].corporate);
                        $("#info_position").val(data[i].contact_position);
                        $("#info_field").val(data[i].business_field);
                        alert(i);
                        
                        $("#contact_name").val(data[i].contact_name);
                        $("#info_address").val(data[i].address);
                        $("#info_website").val(data[i].website);
                        $("#contact_tax").val(data[i].contact_tax);
                        $("#contact_email").val(data[i].contact_email);
                    }
                }
            }
        },
        error: function(data,err){
            console.log(data);
        }
    });
}